var app = getApp();
Page({
    data:{
        sets : {sorttype:0},
        ischeck : false,
        allsort : null,
        actsort : 0,
        sysinfo : {},
        lTop : 0,
        toView : '',
        for : '',
        rarr : [],
        options : {},
        isIPX : app.globalData.isIPX,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        Time : app.globalData.Time,
    },
    onLoad:function(options){
        var self = this;
        self.setData({
            options : options,
        });
        var type = options.f ? options.f : 1;
        app.com.http('sort_v1','POST',{op:'info',type:type},30,false,function(res){
            if (!res.data.errno) {
                self.setData({
                    allsort : res.data.data.allsort,
                    sets : res.data.data.set,
                    type : type,
                    Pagetheme : res.data.data.params.style,
                });

                wx.setNavigationBarTitle({
                  title:  res.data.data.params.title ? res.data.data.params.title : '分类',
                });

            }
            wx.stopPullDownRefresh();
        });

    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: '分类',
            path: '',
        }
    },
    onShareTimeline(){
        return {
            title: '分类',
        }
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            isdown : true,
        });
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
    },
    toggleRightPopup() {
        this.setData({
            showRightPopup: !this.data.showRightPopup,
            searchfocus : !this.data.searchfocus,
        });
    },
    toarticle : function(e){
        var self = this;
        var url = e.currentTarget.dataset.url;
        if( url ) {
            wx.navigateTo({
              url: url
            });
        }
    },
    togoodlist : function( e ){
        var type = e.currentTarget.dataset.type;
        var name = e.currentTarget.dataset.name;
        var turl = this.data.tid ? '&tid='+this.data.tid : '';
        wx.navigateTo({
          url: '/zofui_sitetemp/pages/goodlist/goodlist?sid='+e.currentTarget.dataset.id+'&type='+type+'&sortname='+name+turl,
        })
    },
    changeSort : function(e){
        var self = this;
        if( e.currentTarget.dataset.id == self.data.actsort ) return false;
        if( !self.sysinfo ) {
            wx.getSystemInfo({
                success: function(res) {
                    self.setData({
                        sysinfo : res
                    });
                }
            })
        }
        self.setData({
            actsort : e.currentTarget.dataset.id
        });

        if( self.data.sysinfo.windowHeight - e.detail.y <= 150 ) {
            self.setData({
                lTop : e.detail.y + 50
            });
        }else if( e.detail.y <= 150 ){
            self.setData({
                lTop : e.detail.y - 100
            });
        }

        self.setData({
          toView: 'gsort_r_item'+e.currentTarget.dataset.id
        });
    },
    bindscroll(e){
        console.log(e)
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e,this.data.tid );
    },
    redirectto : function( e ){
        app.com.redirectto( e,this.data.tid );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
})